#include "FormatFilenameBox.h"

FormatFilenameBox::FormatFilenameBox(QWidget *parent) : QWidget(parent)
{
	mainLayout = new QHBoxLayout(this);
	lineEdit = new QLineEdit(this);
	label = new QLabel(this);
	mainLayout -> addWidget(lineEdit);
	mainLayout -> addWidget(label);
	setLayout(mainLayout);
	connect(lineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(SetLabel(const QString&)));
	lineEdit -> setFixedWidth(100);
	label -> setFixedWidth(120);
	lineEdit -> setContentsMargins(0, 0, 0, 0);
	label -> setContentsMargins(0, 0, 0, 0);
	setContentsMargins(0, 0, 0, 0);
	mainLayout -> setAlignment(Qt::AlignmentFlag::AlignCenter);
}

FormatFilenameBox::~FormatFilenameBox()
{
	delete mainLayout;
	delete lineEdit;
	delete label;
}

void FormatFilenameBox::SetLabel(const QString &s)
{
	label -> setText("例: " + GetFormatString(s.toStdString().c_str(), 1));
}

QString FormatFilenameBox::GetFormatString(const char* s, ...)
{
	char tmp[100];

	va_list args;
	va_start(args, s);
	vsprintf(tmp, s, args);
	va_end(args);

	return QString(tmp);
}